///g++ Reading_features.cpp -o example -O2 -larmadillo

#include <omp.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <armadillo>
#include <iomanip>
#include <vector>

using namespace std;
using namespace arma;





void
several_files(std::string list_name, std::string path)
{
  field<string> list_features;
  //list_features.load("./features/train/list.txt");
  list_features.load(list_name);
  int n_matrices = list_features.n_rows;
  
  for (int i = 0; i<n_matrices; ++i)
  {
    
    std::stringstream ssMatrix_name;
    ssMatrix_name << path << list_features(i);
    
    mat mat_feature_vectors; 
    mat_feature_vectors.load( ssMatrix_name.str() );
    
    
    bool is_finite = mat_feature_vectors.is_finite() ;
    bool is_zeroMat =   accu(abs(mat_feature_vectors));
    
    if (!is_finite || is_zeroMat==0 )
    {
      cout << ssMatrix_name.str() << endl;
      cout << "is_finite?? " << is_finite << endl;
      cout << mat_feature_vectors.n_rows << " " << mat_feature_vectors.n_cols << endl;
      //getchar();
    }
    
    for (int j=0;j<mat_feature_vectors.n_cols; j++)
    {
      vec one_vec =  mat_feature_vectors.col(j);
      double is_zero = accu(abs(one_vec));
      
      if (is_zero==0 )
      {
	cout << ssMatrix_name.str() << endl;
	cout << "accu= " << is_zero << endl;
	cout << mat_feature_vectors.n_rows << " " << mat_feature_vectors.n_cols << endl;
	//getchar();
      }
    }
  }
}


int
main(int argc, char** argv)
{
  
  //When I have several matrices   
  std::string list_name = "./features/train/list.txt";
  std::string path = "./features/train/";
  several_files(list_name,  path);
  
  //When I have only one
  //   std::string full_path = "problem_here.dat";
  //   mat mat_feature_vectors; 
  //   mat_feature_vectors.load( full_path);
  //   bool is_finite = mat_feature_vectors.is_finite();
  //   double is_zero = accu(abs(mat_feature_vectors));
  //     
  //   
  //   if (!is_finite || is_zero ==0)
  //   {
    // 
  //     cout << "is_finite?? " << is_finite << ". accu= " << is_zero << endl;
  //     cout << mat_feature_vectors.n_rows << " " << mat_feature_vectors.n_cols << endl;
  //     //getchar();
  //     }
  //   
  return 0;
  
}


